#include "ASLoadingScreen.h"
#include "ASScreenMgr.h"
#include "ASScrMain.h"
#include "..\app\ASAppImgInfo.h"
#include "ASScreenShare.h"
#include "ASScrMain.h"
#include "i18n.h"
#include "..\app\ASAppConst.h"
#include "res_str.h"

static as_loading_screen* s_as_ld_scr_p;

static void as_scr_loading_add_content(as_screen* screen_p)
{
    ASUINT param[1];
    as_rect area;
    as_label* lb_warning;
    area.x = 0;
    area.y = 30;
    area.w = as_get_lcd_width();
    area.h = as_get_lcd_height() - 90;
    param[0] = (ASUINT)SGL_LoadString(STR_WARNING);
    lb_warning = (as_label*)screen_p->add_ctrl(screen_p, AS_CTRL_LABEL, area, 1, (void**)param);
    lb_warning->set_bg_hidden((as_control*)lb_warning, ASTRUE);
    lb_warning->set_text_color((as_control*)lb_warning, SCREEN_SOFTKEY_COLOR);
}

static void as_scr_loading_older_evt(void)
{
    as_screen_manager* scr_mgr = as_get_screen_stack_instance();
    scr_mgr->delete_and_pop_screen();
    as_scr_main_show();
}

static void as_scr_loading_younger_evt(void)
{
    as_exit_app();
}

static void as_scr_loading_button_bar(as_screen* screen_p)
{
    as_screen_create_softkey_bar(screen_p, TEXT_OLDER, TEXT_YOUNGER, as_scr_loading_older_evt, as_scr_loading_younger_evt);
}

void as_loading_screen_init(as_screen* screen_p)
{
    s_as_ld_scr_p = (as_loading_screen*)screen_p;
    screen_p->set_bg_color(screen_p, 0xAE1C1C);
    as_scr_loading_button_bar(screen_p);
    as_scr_loading_add_content(screen_p);
}


void as_loading_screen_deinit(as_screen* screen_p)
{
    AS_UNUSED(screen_p);
}

void as_enter_loading_screen(void)
{
    as_screen_manager* scr_mgr = as_get_screen_stack_instance();
    as_screen* scr_p;
    as_ret ret;
    as_log("as_enter_loading_screen,scr_mgr is 0x%x", scr_mgr);
    ret = scr_mgr->new_and_push_screen(AS_SCREEN_LOADING);
    scr_p = scr_mgr->get_cur_screen();

    if(scr_p)
    {
        scr_p->paint_hdlr(scr_p);
        scr_p->flush_hdlr(scr_p);
    }
}